
package org.upt.dcda.db;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * The persistent class for the orders database table.
 * 
 */
@Entity
@Table(name = "orders")
@NamedQueries(value =
{
		@NamedQuery(name = OrderEntity.VIEW_ALL_ORDERS, query = "SELECT orderm FROM OrderEntity orderm"),
		@NamedQuery(name = OrderEntity.VIEW_USER_ORDERS, query = "SELECT orderm FROM OrderEntity orderm WHERE orderm.user.userId = :userid") })
public class OrderEntity implements Serializable
{

	public static final String		VIEW_ALL_ORDERS		= "view_all_orders";

	public static final String		VIEW_USER_ORDERS	= "view_user_orders";

	private static final long		serialVersionUID	= 1L;

	private int						orderId;

	private Set<OrderItemEntity>	orderitems;

	private UserEntity				user;

	public OrderEntity()
	{
	}

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "order_id")
	public int getOrderId()
	{
		return this.orderId;
	}

	public void setOrderId(int orderId)
	{
		this.orderId = orderId;
	}

	// bi-directional many-to-one association to OrderItemEntity
	@OneToMany(mappedBy = "order", fetch = FetchType.EAGER)
	public Set<OrderItemEntity> getOrderitems()
	{
		return this.orderitems;
	}

	public void setOrderitems(Set<OrderItemEntity> orderitems)
	{
		this.orderitems = orderitems;
	}

	// bi-directional many-to-one association to UserEntity
	@ManyToOne(cascade = CascadeType.REMOVE)
	@JoinColumn(name = "order_user_id")
	public UserEntity getUser()
	{
		return this.user;
	}

	public void setUser(UserEntity user)
	{
		this.user = user;
	}

}
